import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//使用Servlet从ServletContext中读取数据
//从WriterServlet里面存的数据中取出来
@WebServlet("/reader")
public class ReaderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        //1.获取到同一个ServletContext对象
        ServletContext context = this.getServletContext();
        //2.从Context中获取到刚才存的值
        String message = (String) context.getAttribute("message");
        //3.把取出的数据显示出来
        resp.getWriter().write("message: " + message);
    }
}
